<template>
  <div class="i-table-no-border">
    <div>
      <Row type="flex">
        <Col class="marginTop10" span="8">调研时间：</Col>
        <Col class="marginTop10" span="8">调研部门：</Col>
        <Col class="marginTop10" span="8">调研人：{{ surveyMan }}</Col>
        <Col class="marginTop10" span="8"
          >调研区域：
          <Select v-model="strSub3" style="width: 180px">
            <Option
              v-for="item in cityList"
              :value="item.value"
              :key="item.value"
              >{{ item.label }}</Option
            >
          </Select>
        </Col>
        <Col class="marginTop10" span="8">单据号：</Col>
        <Col class="marginTop10" span="16"
          >调研目的：
          <Input
            v-model="surveyTarget"
            placeholder="请输入..."
            style="width: 400px"
          />
        </Col>
        <Col class="marginTop10" span="16"
          >调研总结：
          <Input
            v-model="surveyReault"
            placeholder="请输入..."
            style="width: 400px"
          />
        </Col>
      </Row>
      <Row type="flex" justify="space-between">
        <Col> </Col>
        <Col>
          <Button style="margin-right: 10px" @click="showSkuList"
            >关联SKU</Button
          >
          <Button style="margin-right: 10px" @click="objList"
            >关联竞价对象</Button
          >
          <Button type="primary" @click="setAddSub">保存</Button>
        </Col>
      </Row>
    </div>
    <!-- 表格内容 start  -->
    <Table
      ref="table"
      :columns="columns"
      :data="tableDataList"
      :loading="loading"
      class="ivu-mt"
      stripe
      @on-filter-change="handleFilterChange"
      @on-select="handleSelect"
      @on-select-cancel="handleSelectCancel"
      @on-select-all="handleSelectAll"
      @on-select-all-cancel="handleSelectAllCancel"
    >
      <template slot-scope="{ row }" slot="issueState">
        <Input v-model="row.issueState" placeholder="请输入..." />
      </template>
      <template slot-scope="{ row, index }" slot="salePriceManager">
        <Input
          v-model="row.salePriceManager"
          @input="atinput(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="cashPriceGrossRate">
        <Input
          v-model="row.cashPriceGrossRate"
          @input="atinput1(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="cashPriceActualRate">
        <Input
          v-model="row.cashPriceActualRate"
          @input="atinput2(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="salePriceGrossRate">
        <Input
          v-model="row.salePriceGrossRate"
          @input="atinput3(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="salePriceActualRate">
        <Input
          v-model="row.salePriceActualRate"
          @input="atinput4(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="lastSaleActualRate">
        <Input
          v-model="row.lastSaleActualRate"
          @input="atinput5(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="orderNo">
        <Input
          v-model="row.orderNo"
          @input="atinput6(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="surveyReaultTypeName">
        <Select
          v-model="row.surveyReaultTypeName"
          @on-change="atinput7(row, index)"
          style="width: 100%"
          transfer
        >
          <Option
            v-for="item in select"
            :value="item.value"
            :key="item.value"
            >{{ item.label }}</Option
          >
        </Select>
      </template>
      <template slot-scope="{ row, index }" slot="brand">
        <Input
          v-model="row.detailList.brand"
          @input="atinput8(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="targetName">
        <Input
          v-model="row.detailList.targetName"
          @input="atinput15(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="grade">
        <Input
          v-model="row.grade"
          @input="atinput9(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="standardRate">
        <Input
          v-model="row.standardRate"
          @input="atinput10(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="price">
        <Input
          v-model="row.price"
          @input="atinput11(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="priceActualRate">
        <Input
          v-model="row.priceActualRate"
          @input="atinput12(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="salePrice">
        <Input
          v-model="row.salePrice"
          @input="atinput13(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="reasonable">
        <Input
          v-model="row.reasonable"
          @input="atinput14(row, index)"
          placeholder="请输入..."
        />
      </template>
      <template slot-scope="{ row, index }" slot="action">
        <div v-if="row.actions.length > 2">
          <a @click="handleClickMore(row.actions[0].name, row)">{{
            row.actions ? row.actions[0].label : ""
          }}</a>
          <Divider type="vertical" />
          <Dropdown @on-click="(name) => handleClickMore(name, row)" transfer>
            <a
              >更多
              <Icon type="ios-arrow-down" />
            </a>
            <DropdownMenu slot="list">
              <DropdownItem
                v-for="(item, i) in row.actions.slice(1)"
                :key="i"
                :name="item.name"
              >
                {{ item.label }}
              </DropdownItem>
            </DropdownMenu>
          </Dropdown>
        </div>
        <div v-else>
          <a
            v-if="row.actions"
            @click="handleClickMore(row.actions[0].name, row)"
            >{{ row.actions[0].label }}</a
          >
          <Divider
            v-if="row.actions && row.actions.length > 1"
            type="vertical"
          />
          <a
            v-if="row.actions && row.actions.length > 1"
            @click="handleClickMore(row.actions[1].name, row)"
            >{{ row.actions[1].label }}</a
          >
        </div>
      </template>
    </Table>
    <!-- 表格内容 end  -->
    <!-- 分页 start  -->
    <div class="ivu-mt ivu-text-center">
      <Page
        :total="totalNum"
        show-total
        show-sizer
        transfer
        :current.sync="nowPage"
        @on-change="getData"
        @on-page-size-change="handleChangePage"
      />
    </div>
    <!-- 分页 end  -->
    <Modal
      v-model="showmodal1"
      title="关联sku"
      width="1000"
      @on-ok="skuListSub"
    >
      <Row type="flex">
        <Col span="10"
          >商品名称：<Input
            v-model="productName"
            placeholder="请输入..."
            style="width: 200px"
        /></Col>
        <Col span="10"
          >商品编码：<Input
            v-model="productNo"
            placeholder="请输入..."
            style="width: 200px"
        /></Col>
        <Col span="4"
          ><Button style="margin-right: 10px" @click="qingkongSku">清空</Button>
          <Button type="primary" @click="chaxunSku">查询</Button></Col
        >
      </Row>
      <Tabs :value="productNames" @on-click="onChageProduct">
        <TabPane label="已关联" name="productNames1">
          <Table
            border
            :columns="columns1"
            :loading="loadingSku"
            :data="dataOver1"
          >
            <template slot-scope="{ row, index }" slot="action">
              <a href="#" @click="quxiaoSku(row, index)">{{ row.text }}</a>
            </template>
          </Table>
          <div class="ivu-mt ivu-text-center">
            <Page
              :total="totalNum"
              show-total
              show-sizer
              :current.sync="nowPage"
              @on-change="isGuan"
              @on-page-size-change="handleChangePage1"
            />
          </div>
        </TabPane>
        <TabPane label="未关联" name="productNames2">
          <Table border :columns="columns1" :loading="loadingSku" :data="data1">
            <template slot-scope="{ row, index }" slot="action">
              <a href="#" @click="guanlianSku(row, index)">{{ row.text }}</a>
            </template>
          </Table>
          <div class="ivu-mt ivu-text-center">
            <Page
              :total="totalNum"
              show-total
              show-sizer
              :current.sync="nowPage"
              @on-change="isNoGuan"
              @on-page-size-change="handleChangePage2"
            />
          </div>
        </TabPane>
      </Tabs>
    </Modal>
    <Modal
      v-model="showmodal2"
      title="关联竞价对象"
      width="1000"
      @on-ok="objListSub"
      @on-cancel=""
    >
      <Row type="flex">
        <Col span="10"
          >公式名称：<Input
            v-model="productNameObj"
            placeholder="请输入..."
            style="width: 200px"
        /></Col>
        <Col span="10"
          >联系人：<Input
            v-model="productNoObj"
            placeholder="请输入..."
            style="width: 200px"
        /></Col>
        <Col span="4"
          ><Button style="margin-right: 10px" @click="qingkongObj">清空</Button>
          <Button type="primary" @click="chaxunObj">查询</Button></Col
        >
      </Row>
      <Tabs value="name1" @on-click="onChageBer">
        <TabPane label="已关联" name="name1">
          <Table
            border
            :columns="columns2"
            :data="dataOver2"
            :loading="loadingObj"
          >
            <template slot-scope="{ row, index }" slot="action">
              <a href="#" @click="quxiaoObj(row, index)">{{ row.text }}</a>
            </template>
          </Table>
          <div class="ivu-mt ivu-text-center">
            <Page
              :total="totalNum"
              show-total
              show-sizer
              :current.sync="nowPage"
              @on-change="isGuan"
              @on-page-size-change="handleChangePage3"
            />
          </div>
        </TabPane>
        <TabPane label="未关联" name="name2">
          <Table border :columns="columns2" :data="data2" :loading="loadingObj">
            <template slot-scope="{ row, index }" slot="action">
              <a href="#" @click="guanlianObj(row, index)">{{ row.text }}</a>
            </template>
          </Table>
          <div class="ivu-mt ivu-text-center">
            <Page
              :total="totalNum"
              show-total
              show-sizer
              :current.sync="nowPage"
              @on-change="isGuan"
              @on-page-size-change="handleChangePage4"
            />
          </div>
        </TabPane>
      </Tabs>
    </Modal>
  </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex';
import util from '@/libs/util';
import { ApiRequest } from '@api/basePage';
import tables from '@/mixins/dynamictable'; // 混入通用代码

import qwInput from '@/components/common/formItem/qwInput'; // 表单input组件
import qwSelect from '@/components/common/formItem/qwSelect'; // 表单select组件
import qwDatePicker from '@/components/common/formItem/qwDatePicker'; // 表单日期组件
import qwSelectTree from '@/components/common/formItem/qwSelectTree'; // 表单下拉树组件

import { getBtnsId } from '@/libs/btnsPermission';

// import tableActions from './tableActions'; // 表格操作项
import tableBtns from './tableBtns'; // 表格内部操作按钮

export default {
  mixins: [tables],
  props: {
    dynamicData: {
      type: Object
    },
    pagePath: {
      type: String
    },
    orderState: {
      type: String,
      default: ''
    }
  },
  computed: {
    ...mapState('admin/baseList', [
      'listData',
      'searchFormData',
      'searchFormDataQ'
    ])
  },
  watch: {
    orderState (n, o) {
      this.getData();
    }
  },
  components: {
    qwInput,
    qwSelect,
    qwDatePicker,
    qwSelectTree,
    // tableActions,
    tableBtns
  },
  data () {
    return {
      data1: [],
      dataOver1: [],
      data2: [],
      dataOver2: [],
      showmodal1: false,
      showmodal2: false,
      surveyMan: '',
      productNames: '',
      names: 'name1',
      names2: 'name1',
      productName: '',
      productNo: '',
      productNameObj: '',
      productNoObj: '',
      actions: [],
      specTableData: [],
      util: util,
      basePath: this.dynamicData.basePath, // 拼接基础路径
      loadingSku: false,
      loadingObj: false,
      arrList: [],
      arrList1: [],
      arrList5: [],
      names1: 'name1',
      surveyTarget: '',
      surveyReault: '',
      strSub3: '',
      salePriceManager: '',
      select: [
        {
          label: '调整进价',
          value: '调整进价'
        },
        {
          label: '修改定价原则',
          value: '修改定价原则'
        },
        {
          label: '增加比价对象',
          value: '增加比价对象'
        },
        {
          label: '增加原材料',
          value: '增加原材料'
        },
        {
          label: '无需调整',
          value: '无需调整'
        }
      ],
      cityList: [
        {
          value: '1',
          label: '调研区域1'
        },
        {
          value: '2',
          label: '调研区域2'
        }
      ],
      tableDataList: [],
      columns: [
        {
          title: '分类编码',
          key: 'categoryNo',
          fixed: 'left',
          minWidth: 120
        },
        {
          title: '分类名称',
          key: 'categoryName',
          minWidth: 120
        },
        {
          title: '售价管理周期',
          slot: 'salePriceManager',
          align: 'center',
          minWidth: 120
        },
        {
          title: 'SPU编码',
          key: 'spuNo',
          align: 'center',
          minWidth: 120
        },
        {
          title: 'SKU编码',
          key: 'skuNo',
          align: 'center',
          minWidth: 120
        },
        {
          title: '商品名称',
          key: 'productName',
          align: 'center',
          minWidth: 120
        },
        {
          title: '规格',
          key: 'spec',
          align: 'center',
          minWidth: 120
        },
        {
          title: '商品管理区域',
          key: 'productManagerName',
          align: 'center',
          minWidth: 120
        },
        {
          title: '主单位',
          key: 'mainUnitName',
          align: 'center',
          minWidth: 120
        },
        {
          title: '主单位价格',
          key: 'mainUnitPrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '辅单位',
          key: 'auxiliaryUnitName',
          align: 'center',
          minWidth: 120
        },
        {
          title: '辅单位价格',
          key: 'auxiliaryUnitPrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '价格组',
          key: 'priceGruopName',
          align: 'center',
          minWidth: 120
        },
        {
          title: '面价',
          key: 'facePrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '进价',
          key: 'purchasePrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '成本价',
          key: 'costPrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '现金价',
          key: 'cashPrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '标准毛利率',
          slot: 'cashPriceGrossRate',
          align: 'center',
          minWidth: 120
        },
        {
          title: '实际毛利率',
          slot: 'cashPriceActualRate',
          align: 'center',
          minWidth: 120
        },
        {
          title: '售价',
          key: 'salePrice',
          align: 'center',
          minWidth: 120
        },
        {
          title: '标准毛利率',
          slot: 'salePriceGrossRate',
          align: 'center',
          minWidth: 120
        },
        {
          title: '实际毛利率',
          slot: 'salePriceActualRate',
          align: 'center',
          minWidth: 120
        },
        {
          title: '最近一次调价时间',
          key: 'lastChangeTime',
          align: 'center',
          minWidth: 120
        },
        {
          title: '近12月销售额',
          key: 'lastSaleMoney',
          align: 'center',
          minWidth: 120
        },
        {
          title: '近12月毛利额',
          key: 'lastSaleGrossMoney',
          align: 'center',
          minWidth: 120
        },
        {
          title: '实际毛利率',
          slot: 'lastSaleActualRate',
          align: 'center',
          minWidth: 120
        },
        {
          title: '上游单号',
          slot: 'orderNo',
          align: 'center',
          minWidth: 120
        },
        {
          title: '调研总结',
          align: 'center',
          children: [
            {
              title: '调研结果选择',
              slot: 'surveyReaultTypeName',
              align: 'center',
              width: 120
            },
            {
              title: '调研结果描述',
              key: 'surveyReaultDes',
              align: 'center',
              width: 120
            },
            {
              title: '审核人意见',
              key: 'surveyReaultNote',
              align: 'center',
              width: 120
            }
          ]
        }
      ],
      columns5: [
        {
          title: '',
          align: 'center',
          children: [
            {
              title: '比价对象名称',
              slot: 'targetName',
              align: 'center',
              width: 180
            },
            {
              title: '品牌',
              slot: 'brand',
              align: 'center',
              width: 120
            },
            {
              title: '档次',
              slot: 'grade',
              align: 'center',
              width: 120
            },
            {
              title: '标准差率',
              slot: 'standardRate',
              align: 'center',
              width: 120
            },
            {
              title: '现金价',
              slot: 'price',
              align: 'center',
              width: 120
            },
            {
              title: '现金价实际差率',
              slot: 'priceActualRate',
              align: 'center',
              width: 180
            },
            {
              title: '售价（赊欠3月）',
              slot: 'salePrice',
              align: 'center',
              width: 180
            },
            {
              title: '是否合理',
              slot: 'reasonable',
              align: 'center',
              width: 120
            }
          ]
        }
      ],
      columns1: [
        {
          title: '商品名称',
          key: 'productName',
          align: 'center',
          width: 200
        },
        {
          title: 'sku编码',
          key: 'skuNo',
          align: 'center',
          width: 200
        },
        {
          title: '规格参数',
          key: 'specDetailStr',
          align: 'center',
          width: 200
        },
        {
          title: '品牌',
          key: 'brandName',
          align: 'center',
          width: 200
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          fixed: 'right',
          minWidth: 170
        }
      ],
      columns2: [
        {
          title: '公司名称',
          key: 'compareTargetName',
          align: 'center',
          width: 200
        },
        {
          title: '联系人',
          key: 'compareMan',
          align: 'center',
          width: 200
        },
        {
          title: '联系电话',
          key: 'compareTel',
          align: 'center',
          width: 200
        },
        {
          title: '地址',
          key: 'compareAddress',
          align: 'center',
          width: 200
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          fixed: 'right',
          minWidth: 170
        }
      ]
    };
  },
  created () {
    this.surveyMan = localStorage.getItem('customerName');
  },
  methods: {
    ...mapMutations('admin/baseList', ['setTableRowData']),
    // 获取表格的数据
    getData () {
      let searchParam = [];
      Object.keys(this.searchFormData).forEach((key) => {
        searchParam.push({
          name: key,
          value: this.searchFormData[key]
        });
      });
      Object.keys(this.searchFormDataQ).forEach((key) => {
        searchParam.push({
          name: key,
          value: this.searchFormDataQ[key]
        });
      });
    },
    chaxunSku () {
      this.onChageProduct(this.productNames);
    },
    qingkongSku () {
      this.productName = '';
      this.productNo = '';
      this.onChageProduct(this.productNames);
    },
    chaxunObj () {
      this.onChageBer(this.names2);
    },
    qingkongObj () {
      this.productNameObj = '';
      this.productNoObj = '';
      this.onChageBer(this.names2);
    },
    showSkuList () {
      this.showmodal1 = true;
      this.onChageProduct(this.productNames);
    },
    isGuan () {
      this.names = 'name1';
      let searchParam = [
        {
          name: 'productName',
          value: this.productName
        },
        {
          name: 'spuNo',
          value: this.productNo
        },
        {
          name: 'productName_q',
          value: 'Like'
        },
        {
          name: 'spuNo_q',
          value: 'EQ'
        },
        {
          name: 'skuNoListStr',
          value: this.arrList.join(',')
        },
        {
          name: 'skuNoListStr_q',
          value: 'EQ'
        }
      ];

      let datas1 = {
        nowPage: this.nowPage,
        pageShow: this.pageShow,
        searchParam: JSON.stringify(searchParam)
      };
      let curBtnId = getBtnsId('新增');
      sessionStorage.setItem('buttonId', curBtnId);
      ApiRequest('/sysback/sku/list/getFinishSkuList', 'post', datas1).then(
        (res) => {
          let rData = res;
          if (rData.retData !== '') {
            rData.retData = rData.retData;
          }
          let tableDataList = rData.retData.results;
          tableDataList.forEach((item) => {
            let actions = [];
            actions.push({
              name: 'View',
              label: '取消',
              handleType: 'prop'
            });
            item.actions = actions;
          });
          // 增加表格操作项
          this.dataOver1 = rData.retData.results;
          this.totalNum = rData.retData.totalNum;
          this.loadingSku = false;
          for (var j = 0; j < this.dataOver1.length; j++) {
            this.$set(this.dataOver1[j], 'text', '取消');
          }
        }
      );
    },
    isNoGuan () {
      this.names = 'name2';
      let searchParam = [
        {
          name: 'productName',
          value: this.productName
        },
        {
          name: 'spuNo',
          value: this.productNo
        },
        {
          name: 'productName_q',
          value: 'Like'
        },
        {
          name: 'spuNo_q',
          value: 'EQ'
        },
        {
          name: 'skuNoNotInListStr',
          value: this.arrList.join(',')
        },
        {
          name: 'skuNoNotInListStr_q',
          value: 'EQ'
        }
      ];
      let datas = {
        nowPage: this.nowPage,
        pageShow: this.pageShow,
        searchParam: JSON.stringify(searchParam)
      };
      let curBtnId = getBtnsId('新增');
      sessionStorage.setItem('buttonId', curBtnId);
      ApiRequest('/sysback/sku/list/getFinishSkuList', 'post', datas).then(
        (res) => {
          let rData = res;
          if (rData.retData !== '') {
            rData.retData = rData.retData;
          }
          let tableDataList = rData.retData.results;
          tableDataList.forEach((item) => {
            let actions = [];
            actions.push({
              name: 'View',
              label: '取消',
              handleType: 'prop'
            });
            item.actions = actions;
          });
          // 增加表格操作项
          this.data1 = rData.retData.results;
          this.totalNum = rData.retData.totalNum;
          this.loadingSku = false;
          for (var j = 0; j < this.data1.length; j++) {
            this.$set(this.data1[j], 'text', '关联');
          }
        }
      );
    },
    isGuan1 () {
      this.names2 = 'name1';
      let searchParam = [
        {
          name: 'compareTargetName',
          value: this.productNameObj
        },
        {
          name: 'compareMan',
          value: this.productNoObj
        },
        {
          name: 'compareTargetName_q',
          value: 'Like'
        },
        {
          name: 'compareMan_q',
          value: 'EQ'
        },
        {
          name: 'uuid',
          value: this.arrList5.join(',')
        },
        {
          name: 'uuid_q',
          value: 'IN'
        }
      ];
      let datas1 = {
        nowPage: this.nowPage,
        pageShow: this.pageShow,
        searchParam: JSON.stringify(searchParam)
      };
      ApiRequest('/sysback/salepricerule/baseQueryList', 'post', datas1).then(
        (res) => {
          let rData = res;
          if (rData.retData !== '') {
            rData.retData = rData.retData;
          }
          let tableDataList = rData.retData.results;
          tableDataList.forEach((item) => {
            let actions = [];
            actions.push({
              name: 'View',
              label: '取消',
              handleType: 'prop'
            });
            item.actions = actions;
          });
          // 增加表格操作项
          this.dataOver2 = rData.retData.results;
          this.totalNum = rData.retData.totalNum;
          this.loadingObj = false;
          for (var j = 0; j < this.dataOver2.length; j++) {
            this.$set(this.dataOver2[j], 'text', '取消');
          }
        }
      );
    },
    isNoGuan1 () {
      this.names = 'name2';
      let searchParam = [
        {
          name: 'compareTargetName',
          value: this.productNameObj
        },
        {
          name: 'compareMan',
          value: this.productNoObj
        },
        {
          name: 'compareTargetName_q',
          value: 'Like'
        },
        {
          name: 'compareMan_q',
          value: 'EQ'
        },
        {
          name: 'uuid',
          value: this.arrList5.join(',')
        },
        {
          name: 'uuid_q',
          value: 'NotIN'
        }
      ];
      let datas = {
        nowPage: this.nowPage,
        pageShow: this.pageShow,
        searchParam: JSON.stringify(searchParam)
      };
      ApiRequest('/sysback/salepricerule/baseQueryList', 'post', datas).then(
        (res) => {
          let rData = res;
          if (rData.retData !== '') {
            rData.retData = rData.retData;
          }
          let tableDataList = rData.retData.results;
          tableDataList.forEach((item) => {
            let actions = [];
            actions.push({
              name: 'View',
              label: '取消',
              handleType: 'prop'
            });
            item.actions = actions;
          });
          // 增加表格操作项
          this.data2 = rData.retData.results;
          this.totalNum = rData.retData.totalNum;
          this.loadingObj = false;
          for (var j = 0; j < this.data2.length; j++) {
            this.$set(this.data2[j], 'text', '关联');
          }
        }
      );
    },
    // 商品table切换监听
    onChageProduct (n) {
      this.productNames = n;
      this.nowPage = 1;
      this.pageShow = 10;
      this.loadingSku = true;
      if (n == 'productNames1') {
        this.isGuan();
      } else if (n == 'productNames2') {
        this.isNoGuan();
      }
    },
    // 比价对象table切换监听
    onChageBer (n) {
      this.names2 = n;
      this.nowPage = 1;
      this.pageShow = 10;
      this.loadingObj = true;
      if (n == 'name1') {
        this.isGuan1();
      } else if (n == 'name2') {
        this.isNoGuan1();
      }
    },

    quxiaoSku (row, index) {
      if (row.text == '取消') {
        this.dataOver1[index].text = '已选中';
        for (var i = 0; i < this.arrList.length; i++) {
          if (this.arrList[i] == row.skuNo) {
            this.arrList.splice(i, 1);
          }
        }
      } else {
        this.dataOver1[index].text = '取消';
        this.arrList.push(row.skuNo);
      }
    },
    guanlianSku (row, index) {
      if (row.text == '关联') {
        this.data1[index].text = '已选中';
        this.arrList.push(row.skuNo);
      } else {
        this.data1[index].text = '关联';
        for (var i = 0; i < this.arrList.length; i++) {
          if (this.arrList[i] == row.skuNo) {
            this.arrList.splice(i, 1);
          }
        }
      }
    },
    handleChangePage1 (val) {
      this.pageShow = val;
      this.$nextTick(() => {
        this.isGuan();
      });
    },
    handleChangePage2 (val) {
      this.pageShow = val;
      this.$nextTick(() => {
        this.isNoGuan();
      });
    },
    handleChangePage3 (val) {
      this.pageShow = val;
      this.$nextTick(() => {
        this.isGuan1();
      });
    },
    handleChangePage4 (val) {
      this.pageShow = val;
      this.$nextTick(() => {
        this.isNoGuan1();
      });
    },
    atinput (row, index) {
      this.tableDataList[index].salePriceManager = row.salePriceManager;
    },
    atinput1 (row, index) {
      this.tableDataList[index].cashPriceGrossRate = row.cashPriceGrossRate;
    },
    atinput2 (row, index) {
      this.tableDataList[index].cashPriceActualRate = row.cashPriceActualRate;
    },
    atinput3 (row, index) {
      this.tableDataList[index].salePriceGrossRate = row.salePriceGrossRate;
    },
    atinput4 (row, index) {
      this.tableDataList[index].salePriceActualRate = row.salePriceActualRate;
    },
    atinput5 (row, index) {
      this.tableDataList[index].lastSaleActualRate = row.lastSaleActualRate;
    },
    atinput6 (row, index) {
      this.tableDataList[index].orderNo = row.orderNo;
    },
    atinput7 (row, index) {
      this.tableDataList[index].surveyReaultType = row.surveyReaultTypeName;
      this.tableDataList[index].surveyReaultDes = row.surveyReaultTypeName;
    },
    atinput8 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['brand'] = row.brand;
      }
    },
    atinput15 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['targetName'] = row.targetName;
      }
    },
    atinput9 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['grade'] = row.grade;
      }
    },
    atinput10 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['standardRate'] =
          row.standardRate;
      }
    },
    atinput11 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['price'] = row.price;
      }
    },
    atinput12 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['priceActualRate'] =
          row.priceActualRate;
      }
    },
    atinput13 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['salePrice'] = row.salePrice;
      }
    },
    atinput14 (row, index) {
      for (let i = 0; i < row.detailList.length; i++) {
        this.tableDataList[index].detailList[i]['reasonable'] = row.reasonable;
      }
    },
    objList () {
      this.showmodal2 = true;
      this.getLoBer1(this.names2);
    },
    quxiaoObj (row, index) {
      if (row.text == '取消') {
        this.dataOver2[index].text = '已选中';
        for (var i = 0; i < this.arrList5.length; i++) {
          if (this.arrList5[i] == row.uuid) {
            this.arrList1.splice(i, 1);
            this.arrList5.splice(i, 1);
          }
        }
      } else {
        this.dataOver2[index].text = '取消';
        this.arrList1.push(row);
        this.arrList5.push(row.uuid);
      }
    },
    guanlianObj (row, index) {
      if (row.text == '关联') {
        this.data2[index].text = '已选中';
        this.arrList1.push(row);
        this.arrList5.push(row.uuid);
      } else {
        this.data2[index].text = '关联';
        for (var i = 0; i < this.arrList1.length; i++) {
          if (this.arrList1[i].uuid == row.uuid) {
            this.arrList1.splice(i, 1);
            this.arrList5.splice(i, 1);
          }
        }
      }
    },
    skuListSub () {
      if (this.arrList.length > 0) {
        let myVar2 = this.arrList.join(',');
        let data = {
          skuNos: myVar2
        }
				ApiRequest('/sysback/salepricesurvey/getInfoBySkuNos', 'post', data, true).then(
          (res) => {
            if (res.retStatus == '1') {
              this.$Message.success('关联成功');
              this.showmodal1 = false;
              this.tableDataList = res.retData;
            }
          }
        );
      } else {
        this.showmodal1 = false;
        this.tableDataList = [];
      }
    },
    objListSub () {
      let that = this;
      if (that.tableDataList.length > 0) {
        for (let i = 0; i < that.tableDataList.length; i++) {
          that.tableDataList[i].detailList = that.arrList1;
        }
        if (that.arrList1.length > 0) {
          for (let j = 0; j < that.arrList1.length; j++) {
            that.columns5[j].title = '比价对象' + (j + 1);
            that.columns = that.columns.concat(that.columns5[j]); // 拼接比价对象
          }
        } else {
        }
      } else {
        this.$Message.error('请先关联sku');
      }
    },
    setAddSub () {
      let datas = {
        surveyTarget: this.surveyTarget,
        surveyReault: this.surveyReault,
        surveyArea: this.strSub3,
        detailList: this.tableDataList
      };
      ApiRequest('/sysback/salepricesurvey/addSurvey', 'post', datas).then(
        (res) => {
          if (res.retStatus == '1') {
            this.$Message.success('保存成功');
            this.$router.go(-1);
          }
        }
      );
    },
    handleClickMore (name, row) {
      if (name === 'Delete') {
        this.$Modal.confirm({
          title: '删除操作',
          content: '确定删除此数据吗？',
          onOk: () => {
            let data = {
              uuid: row.uuid
            };
            // 开始请求商品列表
            ApiRequest(
              this.requestApi.delTableList.url,
              this.requestApi.delTableList.type,
              data
            ).then((res) => {
              this.$Message.success('删除成功');
              this.actionsChange();
            });
          }
        });
      } else {
        let obj = {}; // 动作的对象信息
        row.actions.forEach((item) => {
          if (name === item.name) {
            obj = item;
            return false;
          }
        });
        this.setTableRowData(row);
        if (obj.handleType === 'link') {
          // 操作类型为链接时，拼接参数跳转
          let jumpPath = this.basePath + obj.name;
          this.$router.push({
            path: jumpPath,
            query: {
              uuid: row.uuid,
              orderType: row.orderType
            }
          });
        } else if (obj.handleType === 'prop') {
          // 操作类型为弹窗时 打开弹窗
          if (obj.name === 'viewing') {
            this.showPropviewing = true;
          } else if (obj.name === 'view') {
            this.showPropviewing = true;
          } else {
          }
        } else {
          // 操作类型为弹窗时 打开弹窗
        }
      }
    }
  }
};
</script>
<style lang="less" scoped>
.i-table-no-border .ivu-table-header th {
  background: #f8f8f8;
}

.marginTop10 {
  margin: 5px 0;
}
</style>
